<?php

class Profile_model extends Model {
	
	private $table 	= 'admin';
	
	function Profile_model() {
		parent::Model ();
	}
	
	function select_profile() {
		$data = array ();
		
		$query = $this->db->query("SELECT `id`, `name`, `pass`, `email` FROM `$this->table` WHERE `id` = '".get_userid()."' LIMIT 1 ");
		
		if ( $query->num_rows () > 0 ) 
			$data = $query->row_array();
		
		$query->free_result ();
		
		return $data;
	}
	
	/**
	 * Kiểm tra mật khẩu
	 *
	 */
	function check_pass( $pass = '' ) {
				
		$query = $this->db->query("SELECT `pass` FROM `$this->table` WHERE `pass` = '$pass' LIMIT 1 ");		
		if ( $query->num_rows () > 0 ) 
			$tes = 1;
		else 
			$tes = 0;
			
		$query->free_result ();		
		return $tes;
	}
	
	function check_email( $email = '' ) {				
		$query = $this->db->query("SELECT `email` FROM `$this->table` WHERE `email` = '$email' AND `id` != '".get_userid()."' LIMIT 1 ");		
		if ( $query->num_rows () > 0 ) 
			$tes = 1;
		else 
			$tes = 0;	
					
		$query->free_result ();		
		return $tes;
	}
	
	function check_user ( $u = '' ) {				
		$query = $this->db->query("SELECT `name` FROM `$this->table` WHERE `name` = '$u' AND `id` != '".get_userid()."' LIMIT 1 ");		
		if ( $query->num_rows () > 0 ) 
			$tes = 1;
		else 
			$tes = 0;	
					
		$query->free_result ();		
		return $tes;
	}
	
	function update_pass( $p = '' ) {		
			
		$data = array(			
			'pass' => $p
		);						
		$this->db->where( 'id', get_userid() );		
		$this->db->update( $this->table, $data);	
	}
	
	function update_profile( $u = '', $e = '' ) {		
			
		$data = array(			
			'name' 		=> $u,
			'email' 	=> $e
		);						
		$this->db->where( 'id', get_userid() );		
		$this->db->update( $this->table, $data);	
	}
	
}
?>